<template>
    <nav-bar>
        <div slot="left" class="back" @click="backclick">
            <img src="../../../assets/img/common/back.svg" >
        </div>
        <div slot="center" class="title">
            <div v-for="(item ,index) in titles"
                 :key="index"
                 class="titleItem" :class="{ active : index === currentIndex }"
            @click="titleClick(index)">
                {{item}}</div>
        </div>
    </nav-bar>
</template>

<script>
    import  NavBar from  "../../../components/common/navbar/NavBar"

    export default {
        name: "detailNavbar",
        components:{
          NavBar
        },
        data(){
            return{
                titles:['商品', '参数' ,'评论' , '推荐'],
                currentIndex :0
            }
        },
        methods:{
            //将字体颜色与索引值相对应
            titleClick(index){
                this.currentIndex = index
                this.$emit('titleClick' ,index)
            },
            //点击返回的方法
            backclick(){
              this.$router.back()
            }
        }
    }
</script>

<style scoped>
  .title{
      display: flex;
  }

    .titleItem{
        flex :1;
        font-size: 13px;
    }

    .active{
        color: #ff5777;
    }
    .back img{
        margin-top: 10px;
        margin-left: 20px;

    }
</style>